#include "Image.h"


Image::Image(int l, int h,char *nomFichier){
	this->h=h;
	this->w=l;
	this->filename=nomFichier;
	this->pic = new unsigned char[3*h*w*sizeof(unsigned char)];
	this->picTemp = new float[3*h*w*sizeof(float)];
}

void Image::setCouleur(int i, int j, const Couleur &c) {
	this->picTemp[3*this->w*j+3*i]=c.getR();
	this->picTemp[3*this->w*j+3*i+1]=c.getV();
	this->picTemp[3*this->w*j+3*i+2]=c.getB();
}
void Image::addCouleur(int i, int j, const Couleur &c) {
	this->picTemp[3*this->w*j+3*i]+=c.getR();
	this->picTemp[3*this->w*j+3*i+1]+=c.getV();
	this->picTemp[3*this->w*j+3*i+2]+=c.getB();
}
unsigned char * Image::getPic() {
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w ; j++){
			this->pic[3*this->w*j+3*i]=(unsigned char)((int)(this->picTemp[3*this->w*j+3*i]*255));
			this->pic[3*this->w*j+3*i+1]=(unsigned char)((int)(this->picTemp[3*this->w*j+3*i+1]*255));
			this->pic[3*this->w*j+3*i+2]=(unsigned char)((int)(this->picTemp[3*this->w*j+3*i+2]*255));
		}
	}
	return pic;
}